fix(git): add missing argument injection guards#3545
Open
ElliotJLT wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
fix(git): add missing argument injection guards#3545ElliotJLT wants to merge 1 commit intomodelcontextprotocol:mainfrom
ElliotJLT wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
…te_branch, git_log, and git_branch
git_diff and git_checkout already reject user-supplied values starting
with '-' to prevent flag injection (even when a malicious ref exists via
filesystem manipulation). The same defense-in-depth pattern was missing
from four other functions:
- git_show: revision parameter passed directly to repo.commit()
- git_create_branch: branch_name and base_branch unchecked
- git_log: start_timestamp and end_timestamp passed to --since/--until
- git_branch: contains and not_contains passed as raw args to repo.git.branch()
Adds the same startswith("-") guards with matching tests for each function.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
git_diffandgit_checkoutalready reject user inputs starting with-to block flag injection attacks — but four other functions lacked the same protection:git_show,git_create_branch,git_log(timestamps), andgit_branch(contains/not_contains)Context
An attacker with filesystem write access (e.g. via
mcp-filesystem) could create malicious git refs like--format=evilunder.git/refs/heads/. Without the leading-dash check, these values would be passed as flags to git commands via GitPython. The existing guards ongit_diffandgit_checkout(+ tests for malicious refs) demonstrate this threat model is already recognised — this PR closes the remaining gaps.Test plan
git_show,git_create_branch,git_log, andgit_branchgit_showrejects malicious refs even when they exist on disk🤖 Generated with Claude Code